package CreateThreadPool;

import java.util.concurrent.*;

public class MyCreateThreadPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ExecutorService executor = new ThreadPoolExecutor(3,
                5,
                8,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(4),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        //创建出Callable类型的实例对象
        MyCallable callable1 = new MyCallable(100);
        MyCallable callable2 = new MyCallable(200);
        MyCallable callable3 = new MyCallable(300);
        MyCallable callable4 = new MyCallable(400);

        //将任务提交到线程池中
        Future<String> f1 = executor.submit(callable1);
        Future<String> f2 = executor.submit(callable2);
        Future<String> f3 = executor.submit(callable3);
        Future<String> f4 = executor.submit(callable4);

        //拿到结果
        System.out.println(f1.get());
        System.out.println(f2.get());
        System.out.println(f3.get());
        System.out.println(f4.get());

        executor.shutdown();

    }
}
